<template>
    <div class="execution">
        <basic-container>
            <style-page
                :showTabsRight='false'
                :showTabsHeard='false'
            >
                <template slot="tabs">
                    <avue-crud ref="crud"
                        :page.sync="page"
                        :data="tableData"
                        :permission="permissionList"
                        :table-loading="tableLoading"
                        :option="tableOption"
                        @on-load="getList"
                        @search-change="searchChange"
                        @refresh-change="refreshChange"
                        @size-change="sizeChange"
                        @current-change="currentChange"
                        @row-update="handleUpdate"
                        @row-save="handleSave"
                        @row-del="rowDel"
                        @selection-change='selectionchange'
                        @select='singleselect'>
                        <!-- <template slot-scope="scope" slot="menu">
                            <el-link
                                type="primary"
                                @click.stop="handleEdit(scope.row,'read')"
                                >查看</el-link
                            >
                            <el-link
                                style="margin-left:20px"
                                type="primary"
                                @click.stop="handleEdit(scope.row,'next')"
                                >跟进</el-link
                            >
                            <el-link
                                style="margin-left:20px"
                                type="primary"
                                @click.stop="rowDel(scope.row,scope.index)"
                                >删除</el-link
                            >
                        </template> -->
                        <!-- <template slot="status" slot-scope="scope">
                            <span v-if="scope.row.status == 0" style="color: #67c23a"
                                >审核通过</span
                            >
                            <span v-if="scope.row.status == -1" style="color: #409eff"
                                >待审核</span
                            >
                            <span v-if="scope.row.status == -2" style="color: #f56c6c"
                                >审核拒绝</span
                            >
                        </template> -->
                        <template slot="menuLeft">
                            <el-button
                                style="margin-left:20px"
                                type="primary"
                                @click.stop="handercli"
                                >删除</el-button
                            >
                        </template>
                        <template slot="icon" slot-scope="scope">
                            <i :class="scope.row.icon"></i>
                        </template>
                        <template slot="timeLine" slot-scope="scope">
                            <el-radio-group v-model="scope.row.timeLine" @change="radioclick">
                                <el-radio :label="50">是</el-radio>
                                <el-radio :label="0">否</el-radio>
                            </el-radio-group>
                            <span>
                                <el-input placeholder="请输入内容"></el-input>
                            </span>
                        </template>
                    </avue-crud>
                </template>
            </style-page>
        </basic-container>
    </div>
</template>

<script>
    import {fetchList, getObj, addObj, putObj, delObj} from '@/views/saas-client/omscustomer/api/omscustomer'
    import {tableOption, abboption} from '@/views/saas-client/omscustomer/const/omscustomer'
    import {mapGetters} from 'vuex'

    export default {
        name: 'omscustomer',
        data() {
            return {
                searchForm: {},
                tableData: [],
                page: {
                    total: 0, // 总页数
                    currentPage: 1, // 当前页数
                    pageSize: 10 // 每页显示多少条
                },
                tableLoading: false,
                tableOption: tableOption,
                abboption,
                data: [
        {
          id: 0,
          event: '事件1',
          timeLine: 50,
          icon: 'el-icon-time',
          comment: '无'
        },
        {
          id: 1,
          event: '事件1',
          icon: 'el-icon-bell',
          timeLine: 100,
          comment: '无',
          children: [
            {
              id: 2,
              event: '事件2',
              icon: 'el-icon-star-on',
              timeLine: 10,
              comment: '无'
            },
            {
              id: 3,
              event: '事件3',
              timeLine: 90,
              comment: '无',
              children: [
                {
                  id: 4,
                  event: '事件4',
                  timeLine: 5,
                  comment: '无'
                },
                {
                  id: 5,
                  event: '事件5',
                  timeLine: 10,
                  comment: '无'
                },
                {
                  id: 6,
                  event: '事件6',
                  timeLine: 75,
                  comment: '无',
                  children: [
                    {
                      id: 7,
                      event: '事件7',
                      timeLine: 50,
                      comment: '无',
                      children: [
                        {
                          id: 71,
                          event: '事件71',
                          timeLine: 25,
                          comment: 'xx'
                        },
                        {
                          id: 72,
                          event: '事件72',
                          timeLine: 5,
                          comment: 'xx'
                        },
                        {
                          id: 73,
                          event: '事件73',
                          timeLine: 20,
                          comment: 'xx'
                        }
                      ]
                    },
                    {
                      id: 8,
                      event: '事件8',
                      timeLine: 25,
                      comment: '无'
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
            }
        },
        computed: {
            ...mapGetters(['permissions']),
            permissionList() {
                return {
                    addBtn: this.vaildData(this.permissions.omscustomer_edit, false),
                    delBtn: this.vaildData(this.permissions.omscustomer_del, false),
                    editBtn: this.vaildData(this.permissions.omscustomer_edit, false)
                };
            }
        },
        methods: {
            radioclick(){
                console.log(this.data,this.permissions);
            },
            singleselect(e){
                console.log(e[0].children);
            },
            selectionchange(e){
                console.log(e);
            },

            handercli(e){
                console.log(e);
                // this.$refs.crud.toggleRowSelection(e.children[0])
            },
            handleEdit(e){
                console.log(e);
            },
            getList(page, params) {
                this.tableLoading = true
                fetchList(Object.assign({
                    current: page.currentPage,
                    size: page.pageSize
                }, params, this.searchForm )).then(response => {
                    
                    this.tableData = response.data.data.records
                    this.page.total = response.data.data.total
                    this.tableLoading = false
                }).catch(() => {
                    this.tableLoading=false
                })
            },
            rowDel: function (row, index) {
                this.$confirm('是否确认删除?' , '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(function () {
                    return delObj(row.id)
                }).then(data => {
                    this.$message.success('删除成功')
                    this.getList(this.page)
                })
            },
            handleUpdate: function (row, index, done,loading) {
                putObj(row).then(data => {
                    this.$message.success('修改成功')
                    done()
                    this.getList(this.page)
                }).catch(() => {
                    loading();
                });
            },
            handleSave: function (row, done,loading) {
                addObj(row).then(data => {
                    this.$message.success('添加成功')
                    done()
                    this.getList(this.page)
                }).catch(() => {
                    loading();
                });
            },
            sizeChange(pageSize){
                this.page.pageSize = pageSize
            },
            currentChange(current){
                this.page.currentPage = current
            },
            searchChange(form, done) {
                this.searchForm = form
                this.page.currentPage = 1
                this.getList(this.page, form)
                done()
            },
            refreshChange() {
                this.getList(this.page)
            }
        }
    }
</script>
